package com.threegold.listviewsample.slice;

import com.threegold.listviewsample.*;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        findComponentById(ResourceTable.Id_basicUsageBtn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                goTo(BasicUsageAbility.class);
            }
        });

        findComponentById(ResourceTable.Id_headerAndFooterBtn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                goTo(HeaderAndFooterAbility.class);
            }
        });

        findComponentById(ResourceTable.Id_gridListBtn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                goTo(GridListAbility.class);
            }
        });

        findComponentById(ResourceTable.Id_loadMoreBtn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                goTo(LoadMoreAbility.class);
            }
        });

        findComponentById(ResourceTable.Id_emptyViewBtn).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                goTo(EmptyAbility.class);
            }
        });
    }

    private void goTo(Class<? extends Ability> clazz) {
        Operation operation = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withAbilityName(clazz)
                .build();
        Intent intent = new Intent();
        intent.setOperation(operation);
        startAbility(intent);
    }
}
